package com.gitee.dengmin.tenant;

import com.gitee.dengmin.tenant.constants.TenantMap;
import com.gitee.dengmin.tenant.mapper.TenantMapper;
import com.gitee.dengmin.tenant.models.Tenant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Component
public class BootstrapApplicationRunner implements ApplicationRunner {
    @Resource
    private TenantMapper tenantMapper;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        List<Tenant> tenants = tenantMapper.selectList(null);
        log.info("get tenants : {}", tenants);
        tenants.forEach(item -> {
            TenantMap.put(item.getAlias(), item);
        });
    }
}
